package com.sylvan.java.exception;

import com.sylvan.java.entity.Student;
import com.sylvan.java.mapper.StudentMapper;
import com.sylvan.java.responsedata.HttpCode;
import com.sylvan.java.responsedata.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * 测试异常Controller类
 *
 * @author
 * @create 2018-10-22 15:27
 **/
@RestController
@RequestMapping("/execption")
public class ExceptionController {

    @Autowired
    private StudentMapper studentMapper;

    @GetMapping("/test1")
    public ResponseData getData() throws MyException {
        List<Student> allStudents = studentMapper.getAllStudents();
        List<Student> allStudents1 = studentMapper.getAllStudents();
        List<Student> allStudents2 = studentMapper.getAllStudents();
        return new ResponseData(HttpCode.OK , allStudents);
    }

    @GetMapping("/test2")
    public ResponseData getData2(){
        int i = 0;
        for(i = 0 ; i<50 ; i ++){
            Student student = new Student();
            student.setId(UUID.randomUUID().toString().replaceAll("-", ""));
            student.setAge(i+"");
            student.setName("张三+" + i);
            studentMapper.insert(student);
        }
        return new ResponseData(HttpCode.OK);
    }



}
